package com.jt.tenant.action;

import android.content.Context;

import com.jt.tenant.app.JTPath;
import com.jt.tenant.db.JTDB;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

/**
 * Created by Administrator on 2016/3/1.
 */
public class InitDBAction {

    public static JTDB initjtDB(Context context){

        if(!new File(JTPath.jt_DB).exists()){

            try{

                InputStream inputStream = context.getClass().getClassLoader().getResourceAsStream("assets/plate_number_query.db");

                FileOutputStream fileOutputStream = new FileOutputStream(new File(JTPath.jt_DB));

                int len = 0;

                byte[] buffer = new byte[1024];

                while ((len = inputStream.read(buffer)) != -1){

                    fileOutputStream.write(buffer, 0, len);

                    fileOutputStream.flush();

                }

                inputStream.close();

                fileOutputStream.close();

            }catch (Exception e){}

        }

        return new JTDB(context);

    }

}
